<?php

/**
 * 网站默认默认控制器
 */
class SiteController extends Controller
{
	/**
	 * 网站首页
	 */
	public function actionIndex()
	{
		$this->pageTitle='杭州盛睿德纺织有限公司-针织布|提花布|绒布|床垫面料';

		if($_GET['lang']=='en'){
			$ck = new CHttpCookie('lang','en');
			Yii::app()->request->cookies['hobby'] = $ck;

		}elseif($_GET['lang']=='cn'){
			$ck = new CHttpCookie('lang','cn');
			Yii::app()->request->cookies['lang'] = $ck;

		}

		$lang=$this->getLang();
		if($lang=='en'){
			$sql="SELECT `news_info`.`id` as `id`,`en_title` as `title`,`en_name` as `type_name`,`time` FROM `news_info`
			LEFT JOIN `news_type` ON `news_info`.`type_id` = `news_type`.`id` limit 5 ";
		}else{
			$sql="SELECT `news_info`.`id` as `id`,`cn_title` as `title`,`cn_name` as `type_name`,`time` FROM `news_info`
			LEFT JOIN `news_type` ON `news_info`.`type_id` = `news_type`.`id` limit 5 ";
		}
		$newList=Yii::app()->db->createCommand($sql)->queryAll();

//		$sql="SELECT * FROM `site_img_info` WHERE `type`=1 limit 1";
//		$logos=Yii::app()->db->createCommand($sql)->queryAll();
		$sql="SELECT * FROM `site_img_info` WHERE `type`=2 limit 3";
		$banenrs=Yii::app()->db->createCommand($sql)->queryAll();
		$sql="SELECT * FROM `site_img_info` WHERE `type`=3 limit 4";
		$products=Yii::app()->db->createCommand($sql)->queryAll();

		$this->render('/site/index',array('logo'=>$logos[0]['img_url'],'banenrs'=>$banenrs,'products'=>$products,'newList'=>$newList));
	}


	/**
	 *关于我们
     */
	public function actionAbout(){
		$this->render('site/about');
	}

	/**
	 *在线留言
	 */
	public function actionMessages(){

		$this->render('site/messages');
	}

	/**
	 *联系我们
	 */
	public function actionContact(){
		$this->render('site/contact');
	}
	
	public function actionError()
	{
	    if($error=Yii::app()->errorHandler->error)
		{
			//if(Yii::app()->request->isAjaxRequest)
				echo $error['message'];
			// else
			// 	$this->render('site/error', $error);
		}
	}




}